package com.ninghushangbao.ninghu.service.Impl;

import com.ninghushangbao.ninghu.entity.News;
import com.ninghushangbao.ninghu.mapper.NewsMapper;
import com.ninghushangbao.ninghu.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    NewsMapper newsMapper;

    @Override
    public void addNews(News news) {
        news.setCreateTime(new Date());
        news.setUpdateTime(new Date());
        if(news.getStatus().equals("1")){
            news.setLaunchTime(new Date());
        }
        newsMapper.addNews(news);
    }

    @Override
    public List<News> selectNews() {
        return newsMapper.selectNews();
    }

    @Override
    public List<News> selectNewsCompany() {
        return newsMapper.selectNewsCompany();
    }

    @Override
    public List<News> selectNewsGroup() {
        return newsMapper.selectNewsGroup();
    }

    @Override
    public List<News> selectNewsTopic() {
        return newsMapper.selectNewsTopic();
    }

    @Override
    public News selectNewsById(int id) {
        return newsMapper.selectNewsById(id);
    }

    @Override
    public void updateNews(News news) {
        News news1 = newsMapper.selectNewsById(news.getNewsId());
        if(news.getStatus().equals("1")&&news1.getStatus().equals("0")){
            news.setLaunchTime(new Date());
        }
        news.setUpdateTime(new Date());
        newsMapper.updateNews(news);
    }

    @Override
    public void deleteNewsById(List<Integer> newsId) {
        newsMapper.deleteNewsById(newsId);
    }

}
